﻿//=============================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 作 者：孙德响
// 日 期：2011/11/07 
// 描 述: 提示信息管理类
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00   2011/11/07   曾洋           
//=============================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZX.TR.Library;
using ZX.BLL.Extend;
using ZX.DBModule;
using System.IO;
using ZX.Common;
namespace ZX.TR.Bussiness
{
    public partial class BTrAttach : BLL.Extend.BaseBussnies
    {      
        /// <summary>
        /// 构造函数
        /// </summary>
        public BTrAttach()
        {
            this.entity = new TrAttach();
        }
        /// <summary>
        /// 获取所有资料
        /// </summary>
        /// <returns></returns>
        public IList<BaseBussnies> getAttachList()
        {
            return this.GetEntitys<BaseBussnies>("");
        }
        
        /// <summary>
        /// 获取最新资料
        /// </summary>
        /// <returns></returns>
        public IList<V_TrCourse> getAttachList(int tn)
        {
            this.entity = new V_TrCourse();
            return this.GetEntitysBySqlComm<V_TrCourse>("select top " + CSVHelper.FmSQL(tn) + "tc.CourseContent,ta.TrAttachID,ta.Explain, tc.CourseName as CourseName,ta.AttachName as AttachName,ta.Address as Address from TrAttach ta,TrCourse tc where ta.ParentID=tc.TrCourseID and ta.IsFirstPageView='Y'");
        }
        /// <summary>
        /// 获取最新公告，互动
        /// </summary>
        /// <returns></returns>
        public IList<V_TrMessageIssue> getAttachList(int tn,string gghd)
        {
            this.entity = new V_TrMessageIssue();
            return this.GetEntitysBySqlComm<V_TrMessageIssue>("select top " + CSVHelper.FmSQL(tn) + " * from V_TrMessageIssue where MessageType='" + CSVHelper.FmSQL(gghd) + "' and IsPublic='是' order by addtime desc");
        }
       
        /// <summary>
        /// 根据ID删除资料
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public bool delAttachById(Guid guid) {
            return this.delete("AttachID='"+CSVHelper.FmSQL(guid)+"'");
        }
        /// <summary>
        /// 先删除已存在的文件 复制文件到指定位置
        /// </summary>
        /// <param name="file">要复制的文件</param>
        /// <param name="destinationFile">要复制到目标位置的文件</param>
        public void delFile(string file, string destinationFile)
        {
            file = "E:\\test.txt";
            destinationFile = "d:\\tmp\\test.txt";
            if (File.Exists(destinationFile))
            {
                FileInfo fi = new FileInfo(destinationFile);
                if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
                    fi.Attributes = FileAttributes.Normal;
                File.Delete(destinationFile);
            }
            File.Copy(file, destinationFile, true);
        }


        public void delFile(string file)
        {
            file = "E:\\test.txt";
            if (File.Exists(file))
            {
                FileInfo fi = new FileInfo(file);
                if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
                    fi.Attributes = FileAttributes.Normal;
                File.Delete(file);
            }
        }
    }
}
